package com.ai.controller;

import com.ai.interfaces.Group1;
import com.ai.model.IndexRequest;
import com.ai.model.Student;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * @Description
 * @Author zhuangwei
 * @Date 2020/11/26
 */
@Validated
@RestController
public class IndexController {


    @GetMapping("/validate")
    public Object validate(
            @Size(min = 1,max = 10,message = "姓名长度必须为1到10") String name,
            @Min(value = 10,message = "年龄最小为10")
            @Max(value = 100,message = "年龄最大为100") @RequestParam(defaultValue = "101") int age,
            @Pattern(regexp = "^[0-9]{6}$",message = "商品编号不正确") String goodNo) {
        return name + ":" + age + ":" + goodNo;
    }

    @PostMapping("/addName")
    public int validate1(@RequestBody @Validated(Group1.class) IndexRequest indexRequest){

        return 1;
    }
}
